
def main():
	print("欢迎光临!")
	money = float(input("请输入你的卡余额: "))

	shopping_cart = []
	goods_list = [
		{"name": "飞旺", "price": 0.5}, 
		{"name": "吱吱香", "price": 1},
		{"name": "小滑头", "price": 1.5},
		{"name": "小白兔", "price": 2},
		{"name": "旺旺", "price": 3},
		{"name": "可乐", "price": 4}, 
		{"name": "雪碧", "price": 5}, 
		{"name": "果汁", "price": 6},
		{"name": "橙子", "price": 9},
		{"name": "苹果", "price": 8},
		{"name": "香蕉", "price": 5},
		{"name": "西瓜", "price": 3},
		{"name": "火龙果", "price": 10},
		{"name": "榴莲", "price": 20},
		{"name": "飞天茅台", "price": 1000}
	]

	shopping(shopping_cart, goods_list, money)


def shopping(shopping_cart, goods_list, money):

	print("商品列表:")
	for i, goods in enumerate(goods_list):
		print(f"{i + 1}. {goods['name']} - {goods['price']}元")

	while True:
		choice = input("请输入你要购买的商品名称: ")
		if choice.lower() == "q":
			break
		for goods in goods_list:
			if goods['name'] == choice:
				if money >= goods['price']:
					shopping_cart.append(goods)
					money -= goods['price']
					print(f" {goods['name']} 已添加到购物车")
					print(f"恭喜,购买成功!您的卡余额还剩: {money}元")
				else:
					print(f"穷鬼,钱不够!请到其他超市购买")
				break
			
		else:
			print("没有这个商品,别瞎弄!")
			
	print_receipt(shopping_cart)


def print_receipt(shopping_cart):
	print("购物小票:")
	receipt = []
	total = 0
	for goods in shopping_cart:
		if goods in receipt:
			receipt[receipt.index(goods)]["num"] += 1
			receipt[receipt.index(goods)]["total"] += goods["price"]
		else:
			receipt.append({"name": goods["name"], "price": goods["price"], "num": 1, "total": goods["price"]})
		total += goods["price"]

	print ("商品名称        	单价    数量    小计")
	for item in receipt:
		print(f"{item['name']: <20} {item['price']: <8} {item['num']: <8} {item['total']}")
	
	print("-" * 50)
	print(f"总计: {total}元")

	print("谢谢光临!")

main()